package com.roger.tool.utils.mm;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Xml;

public class MyXmlParser {
	

	public static String getChannel(String xml){
		XmlPullParser parser = Xml.newPullParser();
		String channel = null;
		try {
			parser.setInput(new InputStreamReader(new ByteArrayInputStream(xml.getBytes())));
			int eventype = parser.getEventType();
			while(eventype!=XmlPullParser.END_DOCUMENT){
				switch(eventype){
				case XmlPullParser.START_TAG:
					if(parser.getName().equalsIgnoreCase("channel"))
						channel = parser.nextText();
					break;
				}
				eventype = parser.next();
			}
		} catch (XmlPullParserException e) {
//			e.printStackTrace();
		} catch (IOException e) {
//			e.printStackTrace();
		}catch (Exception e) {
//			e.printStackTrace();
		}
		return channel;
	}
	
	public static String getAppId(String xml){
		XmlPullParser parser = Xml.newPullParser();
		String appid = null;
		try {
			parser.setInput(new InputStreamReader(new ByteArrayInputStream(xml.getBytes())));
			int eventype = parser.getEventType();
			while(eventype!=XmlPullParser.END_DOCUMENT){
				switch(eventype){
				case XmlPullParser.START_TAG:
					if(parser.getName().equalsIgnoreCase("APPID"))
						appid = parser.nextText();
					break;
				}
				eventype = parser.next();
			}
		} catch (XmlPullParserException e) {
//			e.printStackTrace();
		} catch (IOException e) {
//			e.printStackTrace();
		}catch (Exception e) {
//			e.printStackTrace();
		}
		return appid;
	}
	
	public static String getProgramdID(String xml){
		XmlPullParser parser = Xml.newPullParser();
		String appid = null;
		try {
			parser.setInput(new InputStreamReader(new ByteArrayInputStream(xml.getBytes())));
			int eventype = parser.getEventType();
			while(eventype!=XmlPullParser.END_DOCUMENT){
				switch(eventype){
				case XmlPullParser.START_TAG:
					if(parser.getName().equalsIgnoreCase("programID"))
						appid = parser.nextText();
					break;
				}
				eventype = parser.next();
			}
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return appid;
	}
}
